﻿using GameData;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using LitJson;
using TNet;
using TNServer;

public class ServerAction
{

    public static void ServerActionRef(TcpPlayer player, BinaryReader reader)
    {
        
        //解析
        string ActionName = reader.ReadString();
        Console.WriteLine("[CS] "+player.address+"请求： "+ActionName);
        switch (ActionName)
        {
            case "CS注册":
                Logic.RegistLogic(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS登录":
                Logic.LoginLogic(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS领取":
                Logic.ReceiveNumLogic(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS统计数据":
                Logic.ReceiveCount(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS抽号":
                Logic.PickNumLogic2(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS抽号数":
                Logic.SetShowNUmLogic(player, reader.ReadInt32());
                break;
            case "CS排号信息":
                Logic.PickAllNumINfo(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS心跳":
                Logic.Heartbeat(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS处理":
                Logic.DueNumber(player, LitJson.JsonMapper.ToObject<NextNumber>(reader.ReadString()));
                break;
            case "CS完成办理":
                Logic.CompleteNumber(player, LitJson.JsonMapper.ToObject<NextNumber>(reader.ReadString()));
                break;
            case "CS放弃办理":
                Logic.CancleNumber(player, LitJson.JsonMapper.ToObject<NextNumber>(reader.ReadString()));
                
                break;
            case "CS处理名单":
                Logic.DueNumberLists(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS设置窗口":
                //SetwindowNum
                Logic.SetwindowNum(player, LitJson.JsonMapper.ToObject<NextNumber>(reader.ReadString()));
                break;
            case "CS呼叫":
                Logic.callNumberInfo(player, LitJson.JsonMapper.ToObject<CallNumber>(reader.ReadString()));
                break;
            case "CS所有名单":
                Logic.GetAllNumber(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS添加数量":
                Logic.AddCurNumCount(player, LitJson.JsonMapper.ToObject<NumberData>(reader.ReadString()));
                break;
            case "CS一次抽取数":
                Logic.SetOncePickNum(player, LitJson.JsonMapper.ToObject<NumberData>(reader.ReadString()));
                break;
            case "CS添加VIP":
                Logic.SetNumToVIP(player, LitJson.JsonMapper.ToObject<SetNumToVIP>(reader.ReadString()));
                break;
            case "CS取号和VIP信息":
                Logic.GetRecAndVIPNum(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS清空数据":
                Logic.ClearData(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS创建VIP":
                
                break;
            case "CS新增号码数量":
                
                Logic.CreateNumByNum(player, LitJson.JsonMapper.ToObject<NumberData>(reader.ReadString()));
                break;
            case "CS设置语种":
               
                Logic.SetSoundType(player, LitJson.JsonMapper.ToObject<SoundType>(reader.ReadString()));
                break;
            case "CS获取语种":
                Logic.GetSoundType(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS信息抽号":
                
                Logic.NumReceiveNumLogic(player, LitJson.JsonMapper.ToObject<CheckNum>(reader.ReadString()));
                break;
            case "CS设置取号方式":
                
                Logic.SetRecType(player, LitJson.JsonMapper.ToObject<RecNumType>(reader.ReadString()));
                break;
            case "CS获取取号方式":
                Logic.GetRecNumType(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS设置数据":
                Logic.SetDataVO(player, LitJson.JsonMapper.ToObject<DataInfo>(reader.ReadString()));
                break;
            case "CS获取数据":
                Logic.GetDataVO(player, LitJson.JsonMapper.ToObject<DataInfo>(reader.ReadString()));
                break;
            case "CS新增客户":
                Logic.NewCustomer(player, LitJson.JsonMapper.ToObject<CustomerData>(reader.ReadString()));
                break;
            case "CS领取所有号码":
                Logic.testRecAllNUm(player, LitJson.JsonMapper.ToObject<UserInfo>(reader.ReadString()));
                break;
            case "CS清空抽号":
                Logic.OnClearPickNum(player, LitJson.JsonMapper.ToObject<DataInfo>(reader.ReadString()));
                break;
            case "CS获取队列信息":
                Logic.OnGetPickNum(player, LitJson.JsonMapper.ToObject<DataInfo>(reader.ReadString()));
                break;
            case "CS获取客户情况":
                Logic.GetCustomers(player, LitJson.JsonMapper.ToObject<DataInfo>(reader.ReadString()));
                break;
        }

    }





}


public class Logic
{
    //公告
    public static void publicSend(string name,string value)
    {
        Console.WriteLine("------ 推送 "+ name + " 消息----");
        BinaryWriter writer = GameServer.instance.BeginSend(Packet.CommonClientPush);
        writer.Write(name);
        writer.Write(value);
        GameServer.instance.EndSend(true);

    }


    public static void S2C_SetSoundType()
    {

        SoundType SoundType = Application.MainVO.SoundType;

        string str = JsonMapper.ToJson(SoundType);
        Logic.publicSend("SC设置语种", str);

    }

    public static void S2C_SetRecNumType()
    {

        RecNumType RecNumType =new RecNumType();
          RecNumType.reNumType  = Application.MainVO.isNumRec;

        string str = JsonMapper.ToJson(RecNumType);
        Logic.publicSend("SC设置取号方式", str);

    }


    /// <summary>
    /// 推送号码数量
    /// </summary>
    public static void S2C_NumberCountInfo()
    {
        NumAllInfo numAllInfo = GetCurNumAllInfo();

        string str = JsonMapper.ToJson(numAllInfo);
        Logic.publicSend("SC统计数据",str);

    }

    public static NumAllInfo GetCurNumAllInfo()
    {
        string curgroup = Application.MainVO.SetDataDic["批次"];
        NumAllInfo numAllInfo = new NumAllInfo();
        numAllInfo.CurCount = Application.MainVO.CurNumber;
        numAllInfo.peopleCount = Application.MainVO.ReceiveDic.Count+ Application.MainVO.PickDic.Count+
            Application.MainVO.CancleDic.Count+ Application.MainVO.DueDic.Count+
            Application.MainVO.ComplectDic.Count;
        numAllInfo.showNum = Application.MainVO.ShowNum;
        numAllInfo.recCount = Application.MainVO.ReceiveDic.Count(p => p.@group== curgroup);
        numAllInfo.duCount = Application.MainVO.DueCallDic[curgroup];
        numAllInfo.completeCount = Application.MainVO.DueCallDic[curgroup];
        numAllInfo.PickNum = Application.MainVO.PickNum;//一次抽号数量
        numAllInfo.cancleCount = Application.MainVO.CancleDic.Count;
        numAllInfo.isRecIdCard = Application.MainVO.isNumRec;
        numAllInfo.SetDataDic = Application.MainVO.SetDataDic;
        numAllInfo.trunName = Application.MainVO.trunName;
        numAllInfo.batchList = Application.MainVO.batchList;
        numAllInfo.PickNumInfo = Application.MainVO.PickNumInfo;
        numAllInfo.numberCountdic = Application.MainVO.numberCountdic;


        return numAllInfo;


    }


    //
    public static void S2C_PickNumInfo(PickNumInfo pickNumInfo)
    {
        //
        Console.WriteLine("推送抽奖信息");
        string str = JsonMapper.ToJson(pickNumInfo);
        Logic.publicSend("SC抽号", str);

    }


    public static void S2C_PickQueueNum(PickNumInfo pickNumInfo)
    {
        Console.WriteLine("推送队列信息");
        string str = JsonMapper.ToJson(pickNumInfo);
        Logic.publicSend("SC队列信息", str);
    }


    
    //
    public static void S2C_PickAllNumINfo()
    {
        PickAllNumInfo pickAllNumInfo = new PickAllNumInfo();
        pickAllNumInfo.NumberInfoList = Application.MainVO.PickDic.Where(p => p.@group == Application.MainVO.SetDataDic["批次"]).ToList();
        pickAllNumInfo.NumberInfoList.Sort(Utils.SortCompare);

        //SC排号信息
        string str = JsonMapper.ToJson(pickAllNumInfo);
        Logic.publicSend("SC排号信息", str);
    }

    //
    public static void S2C_RecAndVIPNum()
    {
        NumListData numListData = new NumListData();
        numListData.list1 = Application.MainVO.ReceiveDic;
        numListData.list2 = Application.MainVO.VipDic;
        //SC排号信息
        string str = JsonMapper.ToJson(numListData);
        Logic.publicSend("SC取号和VIP信息", str);
    }





    public static void S2C_DueNumberInfos()
    {

        DueNuminfos dueNuminfos = new DueNuminfos();
        dueNuminfos.NumberInfoList = Application.MainVO.DueDic;
        dueNuminfos.NumberInfoList.Sort(Utils.SortCompare);
        string str = JsonMapper.ToJson(dueNuminfos);
        Logic.publicSend("SC处理名单", str);
    }

    public static void S2C_SetDataVO()
    {
        SetDataInfoDic setDataInfoDic = new SetDataInfoDic();
        setDataInfoDic.SetDataDic = Application.MainVO.SetDataDic;
        string str = JsonMapper.ToJson(setDataInfoDic);
        Logic.publicSend("SC设置数据", str);
    }


    public static void SetSoundType(TcpPlayer player, SoundType soundType)
    {
        Application.MainVO.SoundType = soundType;
        S2C_SetSoundType();
    }



    public static void testRecAllNUm(TcpPlayer player, UserInfo userInfo)
    {
        //
        Console.WriteLine("------ 领取所有号码----");

        foreach (var p in Application.MainVO.CustomerDatas)
        {
            if ( p.Value.NumerList.Count<=0)
            {
                CheckNum cn = new CheckNum();
                cn.idCard = p.Value.IdCard;
                 InfoToNumer(cn);
            }


        }

        ResponserData rd = new ResponserData();

        string str = JsonMapper.ToJson(rd);
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS领取所有号码");
        writer.Write(str);
        player.EndSend();

    }


    public static void RestartReceiveNum()
    {
        Application.MainVO.AllRDic.Clear();
        Application.MainVO.VipDic.Clear();
        foreach (var p in Application.MainVO.CustomerDatas)
        {
            CheckNum cn = new CheckNum();
            cn.idCard = p.Value.IdCard;
            InfoToNumer(cn);
        }

    }



    public static void SetDataVO(TcpPlayer player, DataInfo dataInfo)
    {
        if (Application.MainVO.SetDataDic.ContainsKey(dataInfo.dataType))
        {
            Application.MainVO.SetDataDic[dataInfo.dataType] = dataInfo.valueStr;
            //设置数据
            Console.WriteLine("--设置数据 " + dataInfo.dataType + " :"+ dataInfo.valueStr);
            if (dataInfo.dataType=="批次")
            {
                Application.MainVO.SetDataDic["当前标识"] = Application.MainVO.GetGroupTag(dataInfo.valueStr);
            }
            S2C_SetDataVO();
        }
        
    }

    public static void NewCustomer(TcpPlayer player, CustomerData customerData)
    {
        //
        customerData.id = DateTime.Now.Ticks.ToString();
        customerData.@group = Application.MainVO.SetDataDic["批次"];
        customerData.groupTag = Application.GlobalDb.GetCurGlobalVO().GetGroupTag(customerData.@group);
        customerData.Number = -1;
        customerData.que = "-1";
        Application.ExcelDataManager.AddCustomerData(customerData);

        NumberData nd = new NumberData();
        nd.value = 1;

        Console.WriteLine("------ CS新增客户 " + customerData.name + " ----"+ customerData.@group);
        string str = JsonMapper.ToJson(nd);
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS新增客户");
        writer.Write(str);
        player.EndSend();
    }


    public static void GetDataVO(TcpPlayer player, DataInfo dataInfo)
    {
        DataInfo resDataInfo = new DataInfo();
        if (Application.MainVO.SetDataDic.ContainsKey(dataInfo.dataType))
        {
            resDataInfo.valueStr = Application.MainVO.SetDataDic[dataInfo.dataType];
        }

        string str = JsonMapper.ToJson(resDataInfo);
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS获取数据");
        writer.Write(str);
        player.EndSend();
    }


    public static void SetRecType(TcpPlayer player, RecNumType recNumType)
    {
        Console.WriteLine("------设置取号方式:----"+recNumType.reNumType);

        Application.MainVO.isNumRec = recNumType.reNumType;
        S2C_SetRecNumType();


    }


    public static void GetRecNumType(TcpPlayer player, UserInfo userInfo)
    {
        RecNumType RecNumType = new RecNumType();
        RecNumType.reNumType = Application.MainVO.isNumRec;
        Console.WriteLine("------获取取号方式:----" + RecNumType.reNumType);

        string str = JsonMapper.ToJson(RecNumType);
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS获取取号方式");
        writer.Write(str);
        player.EndSend();

    }


    public static void ClearData(TcpPlayer player, UserInfo userinfo)
    {
        //
        Application.instance.NewGlobalVO();
        S2C_NumberCountInfo();
    //    S2C_PickAllNumINfo();
        S2C_RecAndVIPNum();
      
        
    }

    public static void GetSoundType(TcpPlayer player,UserInfo userInfo)
    {
        SoundType soundType = Application.MainVO.SoundType;
        string str = JsonMapper.ToJson(soundType);
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS获取语种");
        writer.Write(str);
        player.EndSend();

    }


    public static void CreateNumByNum(TcpPlayer player, NumberData numberData)
    {
        //
        int count = numberData.value;
        SetNumToVIP setNumToVip = new SetNumToVIP();
        setNumToVip.NumberInfoList = new System.Collections.Generic.List<NumberInfo>();
        for (int i = 0; i < count; i++)
        {
            //
            NumberInfo num = NumberManager.instance.CreateNumber(Application.MainVO.SetDataDic["批次"]);
            num.@group = Application.MainVO.SetDataDic["批次"];
            num.groupTag = Application.MainVO.GetGroupTag(num.@group);
            num.isVIP = false;
            setNumToVip.NumberInfoList.Add(num);

        }

        //SetNumToVIP(player, setNumToVip);
        S2C_RecAndVIPNum();
    }


    public static void GetRecAndVIPNum(TcpPlayer player,UserInfo userinfo)
    {

        NumListData numListData = new NumListData();
        numListData.list1 = Application.MainVO.ReceiveDic;
        numListData.list2 = Application.MainVO.VipDic;
        //SC排号信息
        string str = JsonMapper.ToJson(numListData);
        //
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS取号和VIP信息");
        writer.Write(str);
        player.EndSend();

    }



    /// <summary>
    /// 设置显示数量
    /// </summary>
    /// <param name="player"></param>
    /// <param name="num"></param>
    public static void SetShowNUmLogic(TcpPlayer player,int num)
    {
        Application.MainVO.ShowNum = num;
        S2C_NumberCountInfo();
    }


    public static void DueNumber(TcpPlayer player, NextNumber windows)
    {
        string groupname = Application.MainVO.SetDataDic["批次"];

        if (string.IsNullOrEmpty(Application.MainVO.startCallGrpup))
        {
            Application.MainVO.startCallGrpup = groupname;
        }
        //获取号码
        NumberInfo numberInfo =null;

        int cindx = Application.MainVO.DueCallDic[groupname];
        //判断是否在当前圈
        int incount = 0;
        if (Application.MainVO.PickNumInfo != null)
        {
            incount = Application.MainVO.PickNumInfo.curIndex*Application.MainVO.PickNum;
        }

        //
        if (Application.MainVO.PickNumInfo!= null 
            && Application.MainVO.PickNumInfo.AllPickNumberList.Count > 0 
            && Application.MainVO.PickNumInfo.AllPickNumberList.Count > cindx && cindx<incount)
        {

            int cvalue = Application.MainVO.PickNumInfo.AllPickNumberList[cindx];
            numberInfo = new NumberInfo();
            numberInfo.value = cvalue;
            numberInfo.@group = groupname;
            numberInfo.groupTag = Application.MainVO.GetGroupTag(numberInfo.@group);
            numberInfo.state = (int)NumberState.Picked;
            numberInfo.WindowNum = windows.windowsid;
            bool res = true;


            if (res)
            {
                //计算剩余次数
                //


                Application.MainVO.DueDic.Add(numberInfo);
                numberInfo.PrintCount = incount - cindx-1;
                string str = JsonMapper.ToJson(numberInfo);
                BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
                writer.Write("CS处理");
                writer.Write(str);
                player.EndSend();
                //
                //呼叫

                //推送
                CallNumber callNumber = new CallNumber();
                callNumber.numberInfo = numberInfo;
                callNumber.windowsid = windows.windowsid;
                 str = JsonMapper.ToJson(callNumber);
                Logic.publicSend("SC叫号", str);
                //
                S2C_DueNumberInfos();
            }

        }
        else
        {
            
            numberInfo = new NumberInfo();
            numberInfo.value = -1;
            string str = JsonMapper.ToJson(numberInfo);
            BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
            writer.Write("CS处理");
            writer.Write(str);
            player.EndSend();


            //处理名单
            S2C_DueNumberInfos();

        }
    }

    public static void CompleteNumber(TcpPlayer player, NextNumber windows)
    {
        //完成办理
        //
        NumberInfo numberInfo = null;
        int count = Application.MainVO.DueDic.Count;
        for (int i = 0; i < count; i++)
        {
            NumberInfo temp = Application.MainVO.DueDic[i];
            if (temp.WindowNum == windows.windowsid && temp.value == windows.value && temp.@group == windows.groupname)
            {
                numberInfo = temp;
                break;
            }

        }
        if (numberInfo!= null)
        {
            string groupname = Application.MainVO.SetDataDic["批次"];

            int cindx = Application.MainVO.DueCallDic[groupname];
            Application.MainVO.DueCallDic[groupname] = cindx + 1;

            numberInfo.state = (int) NumberState.Complete;
            //完成办理
            Application.MainVO.ComplectDic.Add(numberInfo);
            Application.MainVO.DueDic.Remove(numberInfo);
            
            //通知
           // S2C_NumberCountInfo();
            //
            S2C_DueNumberInfos();
            //
            S2C_PickAllNumINfo();
        }

    }

    /// <summary>
    /// 处理名单
    /// </summary>
    /// <param name="player"></param>
    /// <param name="nextNumber"></param>
    public static void DueNumberLists(TcpPlayer player, UserInfo userInfo)
    {
        //
        DueNuminfos dueNuminfos = new DueNuminfos();
        dueNuminfos.NumberInfoList = Application.MainVO.DueDic;
        dueNuminfos.NumberInfoList.Sort(Utils.SortCompare);
        string str = JsonMapper.ToJson(dueNuminfos);

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS处理名单");
        writer.Write(str);
        player.EndSend();

    }

    //
    public static void callNumberInfo(TcpPlayer player, CallNumber callNumber)
    {
        //推送
        string str = JsonMapper.ToJson(callNumber);
        Logic.publicSend("SC叫号", str);


    }


    /// <summary>
    /// 添加显示数量
    /// </summary>
    /// <param name="player"></param>
    /// <param name="numdata"></param>
    public static void AddCurNumCount(TcpPlayer player, NumberData numdata)
    {
        Application.MainVO.CurNumber += numdata.value;

        NumAllInfo numAllInfo = GetCurNumAllInfo();
        string sendstr = JsonMapper.ToJson(numAllInfo);

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS添加数量");
        writer.Write(sendstr);
        player.EndSend();

        S2C_NumberCountInfo();
        

    }

    /// <summary>
    /// 设置一次抽取数
    /// </summary>
    /// <param name="player"></param>
    /// <param name="numdata"></param>
    public static void SetOncePickNum(TcpPlayer player, NumberData numdata)
    {
        Application.MainVO.PickNum = numdata.value;
        NumAllInfo numAllInfo = GetCurNumAllInfo();
        string sendstr = JsonMapper.ToJson(numAllInfo);

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS一次抽取数");
        writer.Write(sendstr);
        player.EndSend();

        S2C_NumberCountInfo();
    }


    public static void SetNumToVIP(TcpPlayer player, SetNumToVIP numdata)
    {
        int count = numdata.NumberInfoList.Count;
        Console.WriteLine("[CS] 设置VIP 数量" + count);

        if (count<=0)
        {
            return;
        }
        for (int i = 0; i < count; i++)
        {

            //检查是否在抽中名单中
            NumberInfo needTemp = numdata.NumberInfoList[i];
            Console.WriteLine("[CS] 设置号码：" + needTemp.value+" isvip:"+ needTemp.isVIP);

            if (Application.MainVO.checkInRec(needTemp) && !Application.MainVO.checkInVIP(needTemp))
            {
                Console.WriteLine("[CS] 不再VIP列表中");

                NumberInfo numberInfo = Application.MainVO.GetInRec(needTemp.value,needTemp.@group);
                numberInfo.isVIP = true;
                Application.MainVO.VipDic.Add(numberInfo);

            }
            else if(Application.MainVO.checkInRec(needTemp) )
            {
                Console.WriteLine("[CS] 取消VIP-检查");
                if (!needTemp.isVIP)
                {
                    Console.WriteLine("[CS] 取消VIP:"+ needTemp.value+" "+ needTemp.@group);

                    NumberInfo numberInfo = Application.MainVO.GetInRec(needTemp.value,needTemp.@group);
                    numberInfo.isVIP = false;
                    numberInfo = Application.MainVO.GetInVIP(needTemp.value);
                    //
                    //
                    System.Collections.Generic.List< NumberInfo > jk=new System.Collections.Generic.List<NumberInfo>();
                    for (int j = 0; j < Application.MainVO.VipDic.Count; j++)
                    {
                        //
                        NumberInfo nf = Application.MainVO.VipDic[j];
                        if (nf.value == needTemp.value && nf.@group == needTemp.@group)
                        {
                            jk.Add(nf);
                        }
                    }
                    //
                    for (int j = 0; j < jk.Count; j++)
                    {
                        Application.MainVO.VipDic.Remove(jk[j]);

                    }
                }

            }
            else if (!Application.MainVO.checkInRec(needTemp) 
                && !Application.MainVO.checkInVIP(needTemp)
                && !Application.MainVO.checkInCancle(needTemp) 
                && !Application.MainVO.checkInComplete(needTemp)
                && !Application.MainVO.checkInDue(needTemp)
                && !Application.MainVO.checkInPick(needTemp))
            {
                Console.WriteLine("[CS] 添加新VIP "+ needTemp.value+" isvip:"+ needTemp.isVIP);

                //新建一个
                needTemp.isVIP = true;
                needTemp.state = (int) NumberState.Receive;
                Application.MainVO.VipDic.Add(needTemp);
                Application.MainVO.ReceiveDic.Add(needTemp);
                Application.MainVO.CurNumber += 1;
            }
        }
        //

        S2C_RecAndVIPNum();

    }



    public static void GetAllNumber(TcpPlayer player, UserInfo userInfo)
    {
        System.Collections.Generic.List<NumberInfo> numberInfos = new System.Collections.Generic.List<NumberInfo>();
        numberInfos.AddRange(Application.MainVO.DueDic);
        numberInfos.AddRange(Application.MainVO.PickDic);
        numberInfos.AddRange(Application.MainVO.CancleDic);
        numberInfos.AddRange(Application.MainVO.ComplectDic);

        AllNumbers allNumbers = new AllNumbers();
        allNumbers.NumberInfoList = numberInfos;
        allNumbers.NumberInfoList.Sort(Utils.SortCompare);
        string str = JsonMapper.ToJson(allNumbers);

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS所有名单");
        writer.Write(str);
        player.EndSend();

    }


    /// <summary>
    /// 设置窗口号
    /// </summary>
    /// <param name="player"></param>
    /// <param name="nextNumber"></param>
    public static void SetwindowNum(TcpPlayer player, NextNumber nextNumber)
    {
        NumberInfo numberInfo = null;
        int count = Application.MainVO.DueDic.Count;
        for (int i = 0; i < count; i++)
        {
            NumberInfo temp = Application.MainVO.DueDic[i];
            if (temp.WindowNum == nextNumber.windowsid)
            {
                numberInfo = temp;
                break;
            }

        }
        if (numberInfo==null)
        {
            return;
        }
        string str = JsonMapper.ToJson(numberInfo);

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS设置窗口");
        writer.Write(str);
        player.EndSend();


    }

    /// <summary>
    /// 放弃办理
    /// </summary>
    /// <param name="player"></param>
    /// <param name="windows"></param>
    public static void CancleNumber(TcpPlayer player, NextNumber windows)
    {
        //完成办理
        //
        NumberInfo numberInfo = null;
        int count = Application.MainVO.DueDic.Count;
        for (int i = 0; i < count; i++)
        {
            NumberInfo temp = Application.MainVO.DueDic[i];
            if (temp.WindowNum == windows.windowsid && temp.value == windows.value && temp.@group == windows.groupname)
            {
                numberInfo = temp;
                break;
            }

        }
        if (numberInfo != null)
        {
            numberInfo.state = (int)NumberState.Cancle;
            //放弃办理
            Application.MainVO.CancleDic.Add(numberInfo);
            Application.MainVO.DueDic.Remove(numberInfo);

            //通知
            S2C_NumberCountInfo();
            //
      //      S2C_PickAllNumINfo();
        }


    }

    //



    public static void PickAllNumINfo(TcpPlayer player, UserInfo info)
    {

        PickAllNumInfo pickAllNumInfo = new PickAllNumInfo();
        pickAllNumInfo.NumberInfoList = Application.MainVO.PickDic.Where(p=>p.@group == Application.MainVO.SetDataDic["批次"]).ToList();
        pickAllNumInfo.NumberInfoList.Sort(Utils.SortCompare);

        //SC排号信息
        string str = JsonMapper.ToJson(pickAllNumInfo);
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS排号信息");
        writer.Write(str);
        player.EndSend();
    }

    public static void OnGetPickNum(TcpPlayer player, DataInfo dataInfo)
    {

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS获取队列信息");
        PickNumInfo pickNumInfo = Application.GlobalDb.GetCurGlobalVO().PickNumInfo;
        if (pickNumInfo==null)
        {
            pickNumInfo = new PickNumInfo();
        }
        string sendstr = JsonMapper.ToJson(pickNumInfo);
        writer.Write(sendstr);
        player.EndSend();

    }

    /// <summary>
    /// 获取客户信息
    /// </summary>
    /// <param name="player"></param>
    /// <param name="dataInfo"></param>
    public static void GetCustomers(TcpPlayer player, DataInfo dataInfo)
    {
        System.Collections.Generic.List< CustomerSignData > cd = new System.Collections.Generic.List<CustomerSignData>();
        foreach (var p in Application.GlobalDb.GetCurGlobalVO().CustomerDatas)
        {
            //
            CustomerSignData csd = new CustomerSignData();
            csd.name = p.Value.name;
            csd.isSign = p.Value.issign;
            csd.phone = p.Value.phone;
            csd.salename = p.Value.salename;
            csd.numstr="";
            
            for (int i = 0; i < p.Value.NumerList.Count; i++)
            {
                csd.numstr += "号码:" + p.Value.NumerList[i] + "  ";

            }
            cd.Add(csd);

        }
        CustomerSignDataList cl = new CustomerSignDataList();
        cl.csList = cd;

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS获取客户情况");
        string sendstr = JsonMapper.ToJson(cl);
        writer.Write(sendstr);
        player.EndSend();

    }



    public static void OnClearPickNum(TcpPlayer player,DataInfo dataInfo)
    {
        string curGroup = Application.MainVO.SetDataDic["批次"];

        if (dataInfo.valueStr == "完全清空")
        {
            Console.WriteLine("清空队列:完全清空 all-------" );
            Application.MainVO.DueCallDic[curGroup]=0;
            //设置为0
            Application.MainVO.SetPickNum(0);
            Application.MainVO.PickNUmDic[curGroup] = createPickNum();
            PickNumInfo pi = new PickNumInfo();
            pi.NumberInfoList = new System.Collections.Generic.List<NumberInfo>();
            pi.AllPickNumberList = Application.MainVO.PickNUmDic[curGroup];
            pi.curIndex = 0;
            pi.isComplete = 0;
            //
            Application.MainVO.HasPaiweiList[curGroup] = new System.Collections.Generic.List<NumqueInfo>();
            //返回抽号信息
            Application.GlobalDb.GetCurGlobalVO().PickNumInfo = pi;
        }
        else if(dataInfo.valueStr == "后退一步")
        {
            Console.WriteLine("队列:后退一步 <<-----");
            int po = Application.MainVO.GetPickNum();
            if (po>0)
            {
                po = po - 1;
            }
            Application.MainVO.SetPickNum(po);
            //
            Application.GlobalDb.GetCurGlobalVO().PickNumInfo.curIndex = Application.MainVO.GetPickNum();
            Application.GlobalDb.GetCurGlobalVO().PickNumInfo.isComplete = 0;
        }
        //


        //返回抽号信息
        //
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS清空抽号");
        string sendstr = JsonMapper.ToJson(Application.GlobalDb.GetCurGlobalVO().PickNumInfo);
        writer.Write(sendstr);
        player.EndSend();

        //推送

        S2C_PickQueueNum(Application.GlobalDb.GetCurGlobalVO().PickNumInfo);

    }


    //
    public static void PickNumLogic2(TcpPlayer player, UserInfo info)
    {
        
        string curGroup = Application.MainVO.SetDataDic["批次"];
        int count = Application.MainVO.VipDic.Count;
        System.Collections.Generic.List<int> groupPickList = Application.MainVO.PickNUmDic[curGroup];
        //第一次开始 生成所有队列
        //System.Collections.Generic.List<NumberInfo> pl = Application.MainVO.ReceiveDic.Where(p => p.@group == curGroup).ToList();
        //开始
        groupPickList = createPickNum();
        Application.MainVO.PickNUmDic[curGroup] = groupPickList;
        //
        //
        int curQue = Application.MainVO.GetPickNum();


        //
        PickNumInfo pi = new PickNumInfo();
        pi.isComplete = 0;
        if (groupPickList.Count>0)
        {
            int licount = (curQue + 1)*Application.MainVO.PickNum;
            if (licount<= groupPickList.Count)
            {
                curQue++;
                Application.MainVO.SetPickNum(curQue);
                //
                int addpaicount = (curQue) * Application.MainVO.PickNum;
                Application.MainVO.HasPaiweiList[curGroup] = new System.Collections.Generic.List<NumqueInfo>();
                for (int i = 0; i < addpaicount; i++)
                {
                    NumqueInfo nqi = new NumqueInfo();
                    nqi.value = groupPickList[i];
                    //设置
                    //
                    //
                    nqi.que = i + 1;
                    Application.MainVO.HasPaiweiList[curGroup].Add(nqi);
                }
            }
            else
            {
                pi.isComplete = 1;
            }
        }



        pi.NumberInfoList = new System.Collections.Generic.List<NumberInfo>();
        pi.AllPickNumberList = groupPickList;
        pi.curIndex = curQue;
        //返回抽号信息
        Application.GlobalDb.GetCurGlobalVO().PickNumInfo = pi;
        //
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS抽号");
        string sendstr = JsonMapper.ToJson(pi);
        writer.Write(sendstr);
        player.EndSend();


    }

    public static System.Collections.Generic.List<int> createPickNum()
    {
        string curGroup = Application.MainVO.SetDataDic["批次"];
        int count = Application.MainVO.VipDic.Count;
        System.Collections.Generic.List<int> groupPickList = new System.Collections.Generic.List<int>();
        //第一次开始 生成所有队列
        System.Collections.Generic.List<NumberInfo> pl = Application.MainVO.ReceiveDic.Where(p => p.@group == curGroup).ToList();
        //开始
        if (groupPickList.Count <= 0 && pl.Count > 0)
        {

            System.Collections.Generic.List<NumqueInfo> numqueInfos = new System.Collections.Generic.List<NumqueInfo>();
            //获取需要排位的号码
            System.Collections.Generic.List<NumberInfo> needpaiwei = Application.MainVO.VipDic.Where(p => (p.isVIP && p.@group == curGroup)).ToList();
            System.Collections.Generic.List<int> needpaiInts = new System.Collections.Generic.List<int>();//vip的号码位
            //
            System.Collections.Generic.List<NumqueInfo> haspaList = Application.MainVO.HasPaiweiList[curGroup];

            //添加已经抽号的排位
            for (int i = 0; i < haspaList.Count; i++)
            {
                NumqueInfo nf = haspaList[i];
                numqueInfos.Add(nf);
                needpaiInts.Add(nf.value);
            }

            //
            for (int i = 0; i < needpaiwei.Count; i++)
            {
                if (!needpaiInts.Contains(needpaiwei[i].value))
                {
                    NumqueInfo nf = new NumqueInfo();
                    nf.value = needpaiwei[i].value;
                    if (needpaiwei[i].needque > 0)
                    {
                        nf.que = Application.MainVO.GetPickNum()*1000+ needpaiwei[i].needque;

                    }
                    else
                    {
                        nf.que = Application.MainVO.GetPickNum() * 1000+1000 + numqueInfos.Count;
                    }
                    numqueInfos.Add(nf);
                    needpaiInts.Add(needpaiwei[i].value);
                }

            }


            //检查是否住宅的倍数
            // int cns = Application.MainVO.numberCountdic[curGroup];
            int plcount = pl.Count;
            int neaddnum = plcount % Application.MainVO.PickNum;
          //  neaddnum = Application.MainVO.PickNum - neaddnum;
            plcount = plcount + neaddnum;
            //排序
            //号码不满足倍数，添加额外号码
            for (int i = 0; i < neaddnum; i++)
            {
                NumberInfo num = NumberManager.instance.CreateNumber(Application.MainVO.SetDataDic["批次"]);
                num.@group = Application.MainVO.SetDataDic["批次"];
                num.groupTag = Application.MainVO.GetGroupTag(num.@group);
                num.isVIP = false;
            }

            //
            System.Collections.Generic.List<int> tempList = new System.Collections.Generic.List<int>();
            //先加入出事数据
            for (int i = 0; i < plcount; i++)
            {
                int tempint = i + 1;
                if (!needpaiInts.Contains(tempint))
                {
                    tempList.Add(tempint);

                    //
                    NumqueInfo nf = new NumqueInfo();
                    nf.value = tempint;
                    nf.que = 9999;
                    numqueInfos.Add(nf);
                }
            }
            //打乱顺序
            numqueInfos = Utils.GetRandomList(numqueInfos);
            //冒泡排序
            numqueInfos.Sort(Utils.SortCompareNum);
            //插入号码
            for (int i = 0; i < numqueInfos.Count; i++)
            {
                groupPickList.Add(numqueInfos[i].value);
            }
            
            //
            for (int i = 0; i < groupPickList.Count; i++)
            {
                Console.WriteLine(groupPickList.Count + "第" + (i + 1) + "位:" + groupPickList[i]);
            }
            //

        }

        return groupPickList;
    }





    //旧版本抽号
    public static void PickNumLogic(TcpPlayer player, UserInfo info)
    {
        //抽取号码
        //
        System.Collections.Generic.List<NumberInfo> pl = Utils.GetRandomList(Application.MainVO.ReceiveDic.Where(p=>p.@group== Application.MainVO.SetDataDic["批次"]).ToList());
        System.Collections.Generic.List<NumberInfo> newpl = new System.Collections.Generic.List<NumberInfo>();
        System.Collections.Generic.List<int> hascnumList = new System.Collections.Generic.List<int>();
        int count = pl.Count;
        
        if (count>Application.MainVO.PickNum)
        {
            count = Application.MainVO.PickNum;
        }
        int maxcount = count;
        //判断是否有VIP,添加VIP客户
        System.Collections.Generic.List<NumberInfo> viplist =
            Application.MainVO.VipDic.Where(p => p.@group == Application.MainVO.SetDataDic["批次"]).ToList();
        //
        int vipcount = viplist.Count;
        Console.WriteLine("VIP数量:" + vipcount);
        //
        //查找指定位置的VIP
        for (int i = 0; i < count; i++)
        {
            
            for (int j = 0; j < vipcount; j++)
            {
                NumberInfo numberInfo = viplist[j];
                int kcount = (Application.MainVO.GetPickNum());
                kcount = (kcount + 1);
                if (numberInfo.needque == kcount)
                {
                    Application.MainVO.ReceiveDic.Remove(numberInfo);


                    numberInfo.state = (int)NumberState.Picked;
                    Application.MainVO.SetPickNum((Application.MainVO.GetPickNum() + 1));

                    numberInfo.QueueNum = kcount;

                    hascnumList.Add(numberInfo.QueueNum);
                    newpl.Add(numberInfo);
                    Application.MainVO.PickDic.Add(numberInfo);
                    break;
                }
            }

        }

        for (int i = 0; i < newpl.Count; i++)
        {
            //
            NumberInfo numberInfo = newpl[i];
            if (Application.MainVO.VipDic.Contains(numberInfo))
            {
                Application.MainVO.VipDic.Remove(numberInfo);
                viplist.Remove(numberInfo);
            }

            //清空排号
            int recount = Application.MainVO.ReceiveDic.Count;
            NumberInfo temp = null;
            for (int k = 0; k < recount; k++)
            {
                temp = Application.MainVO.ReceiveDic[k];
                if (temp.@group == numberInfo.@group && temp.value == numberInfo.value)
                {
                    Application.MainVO.ReceiveDic.Remove(temp);
                }
            }

        }




        //
        vipcount = viplist.Count;
        count = count - newpl.Count;
        if (vipcount>0)
        {
            for (int i = 0; i < vipcount; i++)
            {
                //
                if (i < count)
                {

                    NumberInfo numberInfo = viplist[i];
                    if (numberInfo.needque >0)
                    {
                        continue;
                        
                    }


                    Console.WriteLine("VIP:" + numberInfo.value);


                    Application.MainVO.ReceiveDic.Remove(numberInfo);
                    //
                    for (int j = 0; j < maxcount; j++)
                    {
                        Application.MainVO.SetPickNum(Application.MainVO.GetPickNum()+1);
                        if (!hascnumList.Contains(Application.MainVO.GetPickNum()))
                        {
                            hascnumList.Add(numberInfo.QueueNum);
                            break;
                        }
                    }

                    

                    numberInfo.state = (int)NumberState.Picked;
                    numberInfo.QueueNum = Application.MainVO.GetPickNum();

                    newpl.Add(numberInfo);
                    Application.MainVO.PickDic.Add(numberInfo);
                }


            }
        }
        //    Application.MainVO.VipDic.Remove(numberInfo);
        for (int i = 0; i < newpl.Count; i++)
        {
            //
            NumberInfo numberInfo = newpl[i];
            if (Application.MainVO.VipDic.Contains(numberInfo))
            {
                Application.MainVO.VipDic.Remove(numberInfo);
                viplist.Remove(numberInfo);
            }
            //清空排号
            int recount = Application.MainVO.ReceiveDic.Count;
            NumberInfo temp = null;
            for (int k = 0; k < recount; k++)
            {
                temp = Application.MainVO.ReceiveDic[k];
                if (temp.@group == numberInfo.@group && temp.value == numberInfo.value)
                {
                    Application.MainVO.ReceiveDic.Remove(temp);
                }
            }
        }
        Console.WriteLine("剩余VIP数量:" + Application.MainVO.VipDic.Count);

        pl = Utils.GetRandomList(Application.MainVO.ReceiveDic.Where(p => p.@group == Application.MainVO.SetDataDic["批次"]).ToList());

        for (int i = 0; i < maxcount; i++)
        {
            if (newpl.Count>= maxcount)
            {
                break;
            }
            NumberInfo numberInfo = null;

            numberInfo = pl[i];
            if (numberInfo.isVIP)
            {
                continue;
            }
            Console.WriteLine("num数:" + numberInfo.value);

            if (Application.MainVO.checkInPick(numberInfo))
            {
                Console.WriteLine("num存在:" + numberInfo.value);

                continue;
            }



            Application.MainVO.ReceiveDic.Remove(numberInfo);
            for (int j = 0; j < maxcount; j++)
            {
                Application.MainVO.SetPickNum(Application.MainVO.GetPickNum()+1);
                if (!hascnumList.Contains(Application.MainVO.GetPickNum()))
                {
                    break;
                }
            }

            numberInfo.state = (int) NumberState.Picked;
            numberInfo.QueueNum = Application.MainVO.GetPickNum();

            newpl.Add(numberInfo);
            Application.MainVO.PickDic.Add(numberInfo);
        }


        Application.MainVO.PickDic.Sort(Utils.SortCompare);

        PickNumInfo pi = new PickNumInfo();
        pi.NumberInfoList = newpl;

        //返回抽号信息
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS抽号");
        string sendstr = JsonMapper.ToJson(pi);
        writer.Write(sendstr);
        player.EndSend();

        S2C_NumberCountInfo();
        //推送抽号信息
        S2C_PickNumInfo(pi);
        //推送排号信息
  //      S2C_PickAllNumINfo();
    }

    /// <summary>
    /// 注册
    /// </summary>
    /// <param name="player"></param>
    /// <param name="info"></param>
    public static void RegistLogic(TcpPlayer player, UserInfo info)
    {
        Console.WriteLine("账户:" + info.username + " 密码：" + info.password);

        //返回数据
        BinaryWriter writer= player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS注册");
        writer.Write(true);
        player.EndSend();



    }


    public static void LoginLogic(TcpPlayer player,UserInfo info)
    {
        Console.WriteLine("------ 登录----");
        Console.WriteLine("账户:" + info.username + " 密码：" + info.password+" 请求登录!");

        if (Application.MainVO==null)
        {
            Console.WriteLine("数据为空!");
        }
        RoleInfo role =Application.MainVO.GetRoleInfo(info.username);
        if (role==null)
        {
            role = new RoleInfo();
            role.ID = -1;
            role.ErrorInfo = "没有该用户";
        }
        Console.WriteLine("设置数据");
        string sendStr = LitJson.JsonMapper.ToJson(role);

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS登录");
        writer.Write(sendStr);
        player.EndSend();

    }

    /// <summary>
    /// 领取号码
    /// </summary>
    /// <param name="player"></param>
    /// <param name="userInfo"></param>
    public static void ReceiveNumLogic(TcpPlayer player,UserInfo userInfo)
    {
        Console.WriteLine("------ 领取号码----");
        Console.WriteLine("账户:" + userInfo.username + " 密码：" + userInfo.password + " 请求领取号码!");
        NumberInfo numinfo = NumberManager.instance.CreateNumber();
        numinfo.PrintCount = 1;
        numinfo.group = Application.MainVO.SetDataDic["批次"];
        numinfo.groupTag = Application.MainVO.GetGroupTag(Application.MainVO.SetDataDic["批次"]) ;
        Console.WriteLine("------ 领取号码:"+numinfo.value);
        string sendstr = JsonMapper.ToJson(numinfo);

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS领取");
        writer.Write(sendstr);
        player.EndSend();
        //统计数据更新
        //S2C_NumberCountInfo();
    }

    /// <summary>
    /// 通过号码领取号码
    /// </summary>
    /// <param name="player"></param>
    /// <param name="info"></param>
    public static void NumReceiveNumLogic(TcpPlayer player, CheckNum info)
    {

        AllNumbers allNumbers = InfoToNumer(info);
        Console.WriteLine("------ 发送获得的号码数量----:" + allNumbers.NumberInfoList.Count);
        for (int i = 0; i < allNumbers.NumberInfoList.Count; i++)
        {
            Console.WriteLine("获取号码:"+ allNumbers.NumberInfoList[i].value);
        }
        string sendstr = JsonMapper.ToJson(allNumbers);
        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS信息抽号");
        writer.Write(sendstr);
        player.EndSend();
        //统计数据更新
      //  S2C_NumberCountInfo();
    }


    public static AllNumbers InfoToNumer(CheckNum info)
    {
        AllNumbers allNumbers = new AllNumbers();
        allNumbers.NumberInfoList = new System.Collections.Generic.List<NumberInfo>();

        System.Collections.Generic.List<CustomerData> lisda = null;
        if (!String.IsNullOrEmpty(info.idCard))
        {
            Console.WriteLine("------ 身份证获取----:" + info.idCard);

            lisda =
                Application.ExcelDataManager.GetCustomerDataByIdCrad(info.idCard);
            //
            Console.WriteLine("------ 找到相同身份证数量----:" + lisda.Count);
            allNumbers.resInfo = "";
        }
        else if (!String.IsNullOrEmpty(info.payNum))
        {
            Console.WriteLine("------ 收据单号获取----:" + info.payNum);

            lisda =
                Application.ExcelDataManager.GetCustomerDataByPayNum(info.payNum);

            Console.WriteLine("------ 找到收据单号数量----:" + lisda.Count);

        }
        //



        for (int i = 0; i < lisda.Count; i++)
        {
            CustomerData cd = lisda[i];
            if (cd.isadmin && allNumbers.NumberInfoList.Count > 0)
            {
                break;
            }
            //获取是否已经获取号码
            NumberInfo num = null;

            //已经获取的号码
            for (int j = 0; j < Application.MainVO.AllRDic.Count; j++)
            {
                NumberInfo temp = Application.MainVO.AllRDic[j];
                if (temp.ID == cd.id)
                {
                    cd.issign = true;
                    num = temp;
                    break;
                }
            }

            if (num != null && cd.isadmin)
            {
                continue;
            }


            if (num == null)
            {
                //创建号码
                num = NumberManager.instance.CreateNumber(cd.@group, cd.isVip, cd.Number);
                num.ID = cd.id;
                num.name = cd.name;
                num.idCrad = cd.IdCard;
                num.isVIP = cd.isVip;
                num.phone = cd.phone;
                num.PrintCount = 1;
                num.isNew = false;
                num.@group = cd.@group;
                num.groupTag = cd.groupTag;
                num.needque = int.Parse(cd.que);
                Console.WriteLine("------ 生成票据----:"+ num.@group +"  "+ num.value);
                cd.issign = true;
                if (!cd.NumerList.Contains(num.value.ToString()))
                {
                    cd.NumerList.Add(num.value.ToString());
                }
                allNumbers.NumberInfoList.Add(num);
            }
            else
            {
                //
                num.PrintCount += 1;
                allNumbers.OtherList.Add(num);
            }

        }

        return allNumbers;
    }



    /// <summary>
    /// CS心跳
    /// </summary>
    /// <param name="player"></param>
    /// <param name="userInfo"></param>
    public static void Heartbeat(TcpPlayer player, UserInfo userInfo)
    {
        NumAllInfo numAllInfo = GetCurNumAllInfo();
        string sendstr = JsonMapper.ToJson(numAllInfo);

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS心跳");
        writer.Write(sendstr);
        player.EndSend();
    }


    /// <summary>
    /// 统计数据
    /// </summary>
    /// <param name="player"></param>
    /// <param name="userInfo"></param>
    public static void ReceiveCount(TcpPlayer player, UserInfo userInfo)
    {

        NumAllInfo numAllInfo = GetCurNumAllInfo();

        string sendstr = JsonMapper.ToJson(numAllInfo);

        BinaryWriter writer = player.BeginSend(Packet.CommonClientAction);
        writer.Write("CS统计数据");
        writer.Write(sendstr);
        player.EndSend();
    }

}



